/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package motiveai.tests;

import com.jme3.font.BitmapText;
import com.jme3.math.Vector3f;
import com.jme3.scene.Spatial;
import motiveai.annotation.DurationOfBehaviour;
import motiveai.components.BehaviourEntity;
import motiveai.factors.Environment;

/**
 *
 * @author oxplay
 */
public class Test2DefendTheChest extends BehaviourEntity<Test2Agent> {

    public Test2DefendTheChest() {
    }

    public boolean canBeUsed(Test2Agent agent, Environment environment) {
        if (!environment.getBooleanFactor("isDefendingChest")) {
            return true;
        }
        return false;
    }

    @Override
    @DurationOfBehaviour(duration = 2f)
    public float behave(Test2Agent agent, Environment environment) {
        Spatial spat = agent.getSpatial();
        BitmapText text = spat.getUserData("text");
        text.setText("Defend the Chest!");
        environment.setBooleanFactor("isDefendingChest", true);
        agent.getSpatial().getControl(MoveControl.class).moveTo(new Vector3f(0, agent.getSpatial().getLocalTranslation().y, 0));
        return 0;
    }
}
